<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Table</title>

    <!-- Styles -->
    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/helper.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
</head>

<body>

<div class="sidebar sidebar-hide-to-small sidebar-shrink sidebar-gestures">
    <div class="nano">
        <div class="nano-content">
            <div class="logo"><a href="index.html">
                <!-- <img src="assets/images/logo.png" alt="" /> --><span>医疗管理系统</span></a></div>
            <ul>
                <li><a class="sidebar-sub-toggle"><i class="ti-layout-grid4-alt"></i> 医疗管理 <span
                        class="sidebar-collapse-icon ti-angle-down"></span></a>
                    <ul>
                        <li><a href="yl-index.html">科室管理</a></li>
                        <li><a href="yl-yisheng.html">医生管理</a></li>
                        <li><a href="yl-huanzhe.html">患者管理</a></li>
                        <li><a href="yl-chuangwei.html">床位查询</a></li>
                    </ul>
                </li>

            </ul>
        </div>
    </div>
</div>
<!-- /# sidebar -->


<div class="header">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div class="float-left">
                    <div class="hamburger sidebar-toggle">
                        <span class="line"></span>
                        <span class="line"></span>
                        <span class="line"></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="content-wrap">
    <div class="main">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-8 p-r-0 title-margin-right">
                    <div class="page-header">
                        <div class="page-title">
                            <h1>Hello, <span>Welcome Here</span></h1>
                        </div>
                    </div>
                </div>
                <!-- /# column -->
                <div class="col-lg-4 p-l-0 title-margin-left">
                    <div class="page-header">
                        <div class="page-title">

                        </div>
                    </div>
                </div>
                <!-- /# column -->
            </div>
            <!-- /# row -->
            <section id="main-content">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-title">
                                <h4>患者查询 </h4>
                                <div id="top">
                                    <label>患者名称:</label><input type="text" id="patientName" name="patientName" class="form-control input-sm" placeholder="" aria-controls="example1">
                                    <label><input type="button" onclick="show()" value="查询" class="btn btn-primary"></label>
                                    <label><input id="add" style="display: none" type="button" onclick="add()" value="添加患者" class="btn btn-primary"></label>
                                </div>

                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table id="table" class="table">
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /# row -->
                <script type="text/javascript" src="jquery-1.8.3.min.js"></script>
                <script>
                    $(function (){
                        show();
                    })
                    var flag = '0'
                    $.ajax({
                        url: "user/getUsername",
                        type: "post",
                        async: false,
                        cache: false,
                        dataType: "text",
                        "success": function (json) {
                            console.log(json)
                            flag = json;
                            if(json=='ok'){
                                // 设置add按钮显示
                                $("#add").css("display","block");
                            }
                        }
                    })
                    function show() {
                        var patientName = $("#patientName").val();
                        $.ajax({
                            url: "patient/selectPatient",
                            type: "post",
                            async: false,
                            data: {"patientName": patientName},
                            cache: false,
                            dataType: "json",
                            "success": function (json) {
                                console.log(json)
                                var var1 = '';
                                var1 = var1 + '<tr>';
                                var1 = var1 + '<th>#</th>';
                                var1 = var1 + '<th style="text-align: center">患者编号</th>';
                                var1 = var1 + '<th style="text-align: center">患者姓名</th>';
                                var1 = var1 + '<th style="text-align: center">患者年龄</th>';
                                var1 = var1 + '<th style="text-align: center">患者性别</th>';
                                var1 = var1 + '<th style="text-align: center">患者血型</th>';
                                if(flag == 'ok'){
                                    var1 = var1 + '<th style="text-align: center">修改</th>';
                                    var1 = var1 + '<th style="text-align: center">删除</th>';
                                    var1 = var1 + '<th style="text-align: center">设置</th>';
                                }
                                var1 = var1 + '</tr>';
                                for (var i = 0; i < json.length; i++) {
                                    var obj = json[i];
                                    var1 = var1 + '<tr>';
                                    var1 = var1 + '<td>' + (i+1) + '</td>';
                                    var1 = var1 + '<td style="text-align: center">' + obj.patientId + '</td>';
                                    var1 = var1 + '<td style="text-align: center">' + obj.patientName + '</td>';
                                    var1 = var1 + '<td style="text-align: center">' + obj.patientAge + '</td>';
                                    var1 = var1 + '<td style="text-align: center">' + obj.patientGender + '</td>';
                                    var1 = var1 + '<td style="text-align: center">' + obj.patientXx + '</td>';
                                    if(flag == 'ok'){
                                        var1 = var1 + '<td style="text-align: center"><input type="button" onclick="upd('+obj.id+')" value="修改患者" class="btn btn-primary"></td>';
                                        var1 = var1 + '<td style="text-align: center"><input type="button" onclick="del('+obj.id+')" value="删除患者" class="btn btn-primary"></td>';
                                        var1 = var1 + '<td style="text-align: center"><input type="button" onclick="set('+obj.id+')" value="设置" class="btn btn-primary"></td>';
                                    }
                                    var1 = var1 + '</tr>';
                                }
                                console.log(var1)
                                $("#table").html(var1);
                            }
                        })
                    }

                    function add(){
                        window.location.href="yl-add-huanzhe.html";
                    }
                    function set(id){
                        window.location.href="yl-set-huanzhe.html?id="+id;
                    }
                    function upd(id){
                        window.location.href="yl-upd-huanzhe.html?id="+id;
                    }
                    function del(id){
                        $.ajax({
                            url: "patient/deletePatient",
                            type: "post",
                            async: false,
                            data: {"id": id},
                            cache: false,
                            dataType: "text",
                            "success": function (json) {
                                alert(json)
                                show();
                            }
                        })
                    }
                </script>

            </section>
        </div>
    </div>
</div>


<!-- jquery vendor -->
<script src="assets/js/lib/jquery.min.js"></script>
<script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
<!-- nano scroller -->
<script src="assets/js/lib/menubar/sidebar.js"></script>
<script src="assets/js/lib/preloader/pace.min.js"></script>
<!-- sidebar -->

<!-- bootstrap -->
<script src="assets/js/lib/bootstrap.min.js"></script>
<script src="assets/js/scripts.js"></script>
<!-- scripit init-->


</body>

</html>
